<?php

namespace Swof\Http;

class WebSocketRequest extends Request
{
    protected static $connections = [];

    public static function initialize(\Swoole\Http\Request $swoRequest)
    {
        $request = app('wsRequest');

        $fd = $swoRequest->fd;

        self::$connections[$fd]['request'] = $swoRequest;
        self::$connections[$fd]['path'] = $swoRequest->server['path_info'];

        return $request;
    }

    public function setMethod(string $method): WebSocketRequest
    {
        $this->method = $method;

        return $this;
    }

    public function setRequestUri(string $uri): WebSocketRequest
    {
        $this->requestUri = $uri;

        return $this;
    }

    public static function get(int $fd)
    {
        return self::$connections[$fd];
    }

    public static function del(int $fd)
    {
        unset(self::$connections[$fd]);
    }
}